<?php
declare (strict_types = 1);

namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;
class AdminUser extends Model
{
    use SoftDelete;
     protected $deleteTime = "delete_time";

     //定义一对多关联
    //  public function userscore()
    //  {
    //      return $this->hasMany(AdminUserscore::class,"openid","openid");
    //  }
    // 获取列表
    public static function getList()
    {
        $where = [];
        $limit = input('get.limit');
        
               //按openid查找
               if ($openid = input("openid")) {
                   $where[] = ["openid", "like", "%" . $openid . "%"];
               }
               //按昵称查找
               if ($nickname = input("nickname")) {
                   $where[] = ["nickname", "like", "%" . urlencode($nickname) . "%"];
               }
               //按是否启用查找
               if ($status = input("status")) {
                   $where[] = ["status", "like", "%" . $status . "%"];
               }
        $list = self::order('id','desc')->where($where)->paginate($limit);
        return ['code'=>0,'data'=>$list->items(),'extend'=>['count' => $list->total(), 'limit' => $limit]];
    }
    // 判断用户是否已经添加过了
    public static function findbyopenid($openid)
    {
        return self::where('openid',$openid)->find();
    }
}
